/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package studente;

import ejb.GestoreArticoloLocal;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import jpa.Articolo;

/**
 *
 * @author Administrator
 */
@ManagedBean(name="CercaArticolo")
@SessionScoped
public class CercaArticolo {

    @EJB
    GestoreArticoloLocal ga;

    private String termine;
    private String cercaPer;
    private List<Articolo> result;
    private String message;



    /** Creates a new instance of RicercaArticolo */
    public CercaArticolo() {
    }


    public String getTermine() {
        return termine;
    }

    public void setTermine(String termine) {
        this.termine = termine;
    }

    public String getCercaPer() {
        return cercaPer;
    }

    public void setCercaPer(String cercaPer) {
        this.cercaPer = cercaPer;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Collection<Articolo> getResult() {
        if (result != null) {
            return Collections.unmodifiableCollection(result);
        }
        return null;
        //return Lists.unmodifiableCollection(result);
    }

    public void setResult(List<Articolo> result) {
        this.result = result;
    }



    public String getMessage() {
        return message;
    }

    public String cerca(){
        result = ga.ricerca(termine, cercaPer);
        if(result.isEmpty()){
            message = "La ricerca non ha prodotto risultati";
            return "noRisultati";
        }
        message = "";
        return "studenteRis";
    }

    public void riempiDB(){
        ga.riempiDB();
    }

}
